#pragma once
#include <iostream>
#include <vector>

struct ListNode
{
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
};
ListNode *CreateLinkedList(std::vector<int> arr)
{
    if (arr.size() == 0)
        return nullptr;
    ListNode *head = new ListNode(arr[0]);
    ListNode *current = head;
    for (size_t i = 1; i < arr.size(); i++)
    {
        ListNode *temp = new ListNode(arr[i]);
        current->next = temp;
        current = temp;
    }
    return head;
}
ListNode *CreateLinkedList(const int arr[], int n)
{
    if (n == 0)
        return nullptr;
    ListNode *head = new ListNode(arr[0]);
    ListNode *current = head;
    for (size_t i = 1; i < n; i++)
    {
        ListNode *temp = new ListNode(arr[i]);
        current->next = temp;
        current = temp;
    }
    return head;
}

void PrintLinkedList(const ListNode *head)
{
    while (head != nullptr)
    {
        std::cout << head->val << ",";
        head = head->next;
    }
    std::cout << std::endl;
}

void DeleteLinkedList(ListNode *head)
{
    ListNode *current = head;
    while (current != nullptr)
    {
        ListNode *temp = current->next;
        delete current;
        current = temp;
    }
}
